﻿using CommonTools;
using shop.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace shop.Bll.trade
{
    /// <summary> 出库单 </summary>
    public class StockOutBll_old
    {

        ///// <summary> 保存出库记录 </summary>
        //public async Task<Result> SaveStockOutItems(IEnumerable<stockout_order_query_tradeItem> items)
        //{
        //    if(items == null || items.Any()== false)
        //    {
        //        return new Result(true);
        //    }

        //    //检查不要重复添加 
        //    //删除旧的
        //    var arr = items.Select(a => a.stockout_id).ToArray();

        //    await DB.FSql.Delete<stockout_order_query_tradeItem>()
        //        .Where(a => arr.Contains(a.stockout_id))
        //        .ExecuteAffrowsAsync();

        //    await DB.FSql.Insert(items)
        //        .ExecuteSqlBulkCopyAsync();
            
        //    return new Result(true);
        //}


        /// <summary> 查询本地出库数据 </summary>
        public async Task<PageQueryResult<dynamic>> QueryOutStock(DateTime begin, DateTime end, int pageNo, int pageSize)
        {
            //begin = begin.Date;
            //end = end.LastTimeOfDay();

            ////快递老板
            //var logiInfo = await DB.FSql.Select<LogiInfo>()
            //    .Where(a => a.isdel == false && a.logistics_no != string.Empty)
            //    .ToListAsync(a => new
            //    {
            //        a.logistics_no,
            //        a.LogiAcct,
            //        a.IsAgent,
            //        a.logistics_name,
            //    });

            //var list = (await DB.FSql.Select<stockout_order_query_tradeItem>()
            //    .Where(a => a.consign_time >= begin && a.consign_time <= end)
            //    .Count(out var c)
            //    .Page(pageNo, pageSize)
            //    .ToListAsync(a => new
            //    {
            //        发货时间 = a.consign_time,
            //        物流单号 = a.logistics_no,
            //        货品数量 = a.goods_count,
            //        预估邮资 = a.calc_post_cost,
            //        货品总成本 = a.goods_total_cost,
            //        邮费 = a.post_fee,
            //        订单编号 = a.trade_no,
            //        原始单号 = a.src_trade_no,
            //        a.trade_type,
            //        //订单类型 = stockout_order_query_tradeResult.GetTradeTypeText(a.trade_type),
            //        仓库 = a.warehouse_name,
            //        店铺 = a.shop_name,
            //        收货地区 = a.receiver_district,
            //        收货城市 = a.receiver_city,
            //        物流公司 = a.logistics_name,
            //        //快递老板 = a.logistics_template_id,
            //        客服备注 = a.cs_remark,
            //        a.logistics_code,
            //        a.logistics_id,
            //        a.logistics_name,
            //        //a.logistics_name,
            //    }))
            //    .Select(a => {
            //        var info = (logiInfo.FirstOrDefault(x => x.logistics_name == a.logistics_name));
            //        return new
            //        {
            //            a.发货时间,
            //            a.物流单号,
            //            a.物流公司,
            //            物流编号 = a.logistics_code,
            //            快递老板 = info?.LogiAcct,
            //            是否代发= info?.IsAgent ?? false,
            //            a.货品数量,
            //            a.预估邮资,
            //            a.货品总成本,
            //            a.邮费,
            //            a.订单编号,
            //            a.原始单号,
            //            订单类型 = stockout_order_query_tradeResult.GetTradeTypeText(a.trade_type),
            //            a.仓库,
            //            a.店铺,
            //            a.收货地区,
            //            a.收货城市,
            //            //a.快递老板,
            //            a.客服备注,
            //        };
            //    }).ToList();


            //return new PageQueryResult<dynamic>(true, null, list, c);
            return new PageQueryResult<dynamic>(true, null, null, 0);

        }






    }
}
